﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;

namespace Kinlo.UI.Main.Converter
{
    public class TotalWeightResultConverter : IMultiValueConverter
    {
        float Min, Max;
        public TotalWeightResultConverter()
        {
            float min, max;
            min = 261;
            max = 271;
            if (float.TryParse(ConfigurationManager.AppSettings["MinVal"], out min))
            {
                Min = min;
            }
            if (float.TryParse(ConfigurationManager.AppSettings["MaxVal"], out max))
            {
                Max = max;
            }
        }
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            try
            {
                float val; 
                float.TryParse(values[0].ToString(), out val);
                var cell = values[1] as DataGridRow;
                if (val >= Min && val <= Max)
                {
                    return DependencyProperty.UnsetValue;
                    //return cell.Background;
                }
                else
                {
                    return Brushes.Red;
                }
            }
            catch (Exception ex)
            {
                //throw ex;
                return DependencyProperty.UnsetValue;
            }
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    } 


}
